﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Xml.Serialization;
using System.IO;
using System.Configuration;

namespace Microsoft.Mtool.FSM
{
    [Serializable]
    public class TokenImpl : ActionImpl
    {
        public static string ToCDataString(string str)
        {
            return "<![CDATA[" + str + "]]>";
        }

        public static string FromCDataString(string value)
        {
            if (value.StartsWith("<![CDATA["))
                return value.Substring(9, value.Length - 12);
            return value;
        }

        override internal void GenDefaults()
        {
            if (this.InParas != null)
            {
                foreach (Parameter p in this.InParas) p.Var.Name = p.Name;
            }
            if (this.OutParas != null)
            {
                foreach (Parameter p in this.OutParas) p.Var.Name = p.Name;
            }
        }

        public override ActionImpl GetCopy()
        {
            TokenImpl newImpl = new TokenImpl();
            newImpl.Name = this.Name;
            if (this.InParas != null)
            {
                newImpl.InParas = new List<Parameter>();
                foreach (Parameter p in this.InParas) newImpl.InParas.Add(p.GetCopyWithoutVarValues());
            }
            if (this.OutParas != null)
            {
                newImpl.OutParas = new List<Parameter>();
                foreach (Parameter p in this.OutParas) newImpl.OutParas.Add(p.GetCopyWithoutVarValues());
            }
            newImpl.GenDefaults();
            return newImpl;
        }

        public override string ToString()
        {
            return string.Format("[Token]{0}", Name);
        }
    }
}
